package com.fishery.authority.service.impl;

import com.fishery.authority.entity.User;
import com.fishery.authority.entity.UserDetailsImpl;
import com.fishery.authority.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author 白sa能
 * @className
 * @date Created in 2:42 PM 1/20/21
 * @package com.fishery.ucenter.service.impl
 * @Description
 */
@Service
@Component
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String loginId) throws UsernameNotFoundException {
        // 查询用户信息
        User user = userMapper.selectById(loginId);
        if (user != null){
            // 组装参数
            UserDetailsImpl userDetailsImpl = new UserDetailsImpl(user);
//            UserDetailsImpl userDetailsImpl = new UserDetailsImpl();
//            BeanUtils.copyProperties(user, userDetailsImpl);
            return userDetailsImpl;
        }
        return null;
    }
}
